package com.sinszm.wx.pay.order;

import com.googlecode.protobuf.format.JsonJacksonFormat;
import com.sinszm.wx.pay.AbstractPay;
import com.sinszm.wx.pay.PayApi;
import com.sinszm.wx.pay.util.PayCallUtil;
import com.sinszm.wx.properties.BasicWxProperties;
import com.sinszm.wx.protocol.Wx;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 小程序支付
 *
 * @author chenjianbo
 */
@Service
public class MiniApp extends AbstractPay implements PayApi {

    protected MiniApp(BasicWxProperties properties, HttpServletRequest request, JsonJacksonFormat jsonJacksonFormat) {
        super(properties, request, jsonJacksonFormat);
    }

    @Override
    public Wx.Bean.PayResp notificationPaymentResult(HttpServletRequest request, Wx.Bean.PayReq payReq) {
        return PayCallUtil.notificationPaymentResult(this, request, payReq);
    }

    @Override
    public Wx.Bean.PayResp unifiedorder(Wx.Bean.PayReq payReq, Wx.Bean.SceneInfo scene, Wx.Bean.SceneInfoPro scenePro) {
        payReq = payReq.toBuilder().setTradeType("JSAPI").build();
        return PayCallUtil.unifiedorder(this, payReq, scene, scenePro);
    }

    @Override
    public Wx.Bean.PayResp orderquery(Wx.Bean.PayReq payReq) {
        return PayCallUtil.orderquery(this, payReq);
    }

    @Override
    public Wx.Bean.PayResp closeorder(Wx.Bean.PayReq payReq) {
        return PayCallUtil.closeorder(this, payReq);
    }

    @Override
    public Wx.Bean.PayResp refund(Wx.Bean.PayReq payReq, InputStream cert) {
        return PayCallUtil.refund(this, payReq, cert);
    }

    @Override
    public Wx.Bean.PayResp refundquery(Wx.Bean.PayReq payReq) {
        return PayCallUtil.refundquery(this, payReq);
    }

    @Override
    public Wx.Bean.PayResp report(Wx.Bean.PayReq payReq, List<Wx.Bean.Trades> trades) {
        Map<String, String> changeKey = new HashMap<>(0);
        changeKey.put("execute_time", "execute_time_");
        return PayCallUtil.report(this, payReq, trades, changeKey);
    }

    @Override
    public Wx.Bean.PayResp batchquerycomment(Wx.Bean.PayReq payReq, InputStream cert) {
        return PayCallUtil.batchquerycomment(this, payReq, cert);
    }

}
